<template>
    <div>
         <h1>房态新增</h1>


         <table class="table">
            <tbody>
                 <tr>
                    <td>房态名称</td>
                    <td><input type="text" v-model="data.houseName"></td>
                 </tr>
                 <tr>
                    <td>状态</td>
                    <td>
                        <input type="checkbox" v-model="data.state" checked>选择为启用,未选择为禁用
                    </td>
                 </tr>
                 <tr>
                    <td>数量</td>
                    <td><input type="text" v-model="data.sum"></td>
                 </tr>
                 <tr>
                    <td>电话</td>
                    <td><input type="text" v-model="data.phone"></td>
                 </tr>
                 <tr>
                    <td colspan="2">
                        <input type="button" value="添加" @click="add">
                    </td>
                 </tr>
            </tbody>
         </table>
    </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router' 

const router=useRouter();
const data = ref({
  "id": 0,
  "houseName": "",
  "state": true,
  "sum": "",
  "phone": ""
})

const add =()=>{

    if(data.value.houseName=="")
{
alert("房态名称不能为空")
return;
}
if(data.value.phone=="")
{
alert("电话不能为空")
return;
}

  axios.post("https://localhost:7206/api/Login/AddHouse",data.value).then(res=>{
    if(res.data>0)
   {
      alert("添加成功");
      router.push({path:"/show"})
      return;
   }
   else{
    alert("登录失败")
    return;
   }
  })
}

</script>

<style scoped>

</style>